#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:use_collections2.py
# author:jackiex
# datetime:2021/2/19 14:41
# software: PyCharm
'''
    Counter模块使用
'''

#统计词频
#1-传统方式
# colors = ['red', 'blue', 'red', 'green', 'blue', 'blue']
# result = {}
# for color in colors:
#     if result.get(color)==None:
#         result[color]=1
#     else:
#         result[color]+=1
# print (result)

#2---使用Counter统计词频
# from collections import Counter
# colors = ['red', 'blue', 'red', 'green', 'blue', 'blue']
# c = Counter(colors)
# print (dict(c))
# #
# mystr = 'adabaecqcadeqe'
# res = Counter(mystr)
# print(res)
# for k,v in res.items():
#     print(k,':',v)
#
# print(res.most_common(3))  #取出现频度最高的3个元素